home *** CD-ROM | disk | FTP | other *** search
/ 500 MB Nyheder Direkte fra Internet 2 / 500 MB nyheder direkte fra internet CD 2.iso / start / data / text / faq-1415.txt < prev    next >
Text File  |  1995-05-04  |  56KB  |  1,555 lines

  1. Posted-By: auto-faq 3.1.1.2
  2. Archive-name: tcl-faq/usage
  3. Posting-Frequency: monthly
  4.  
  5.  
  6.                    TCL LANGUAGE USAGE QUESTIONS AND ANSWERS
  7.  
  8. INTRODUCTION
  9.  
  10.    This FAQ file is intended to address some of the most commonly asked
  11.    questions regarding the Tcl programming language. It is hoped that by
  12.    addressing these here in this document, that the postings to
  13.    comp.lang.tcl will be of a less repetitive and more informative
  14.    nature. It is also hoped that via this and other available resources,
  15.    more and more people will be able to utilize Tcl and Tcl based
  16.    applications.
  17.  
  18.    This FAQ is maintained by Joe Moss (joe@morton.rain.com) and is posted
  19.    monthly to comp.lang.tcl and news.answers and can also be obtained
  20.    from the Tcl archive at ftp.aud.alcatel.com (198.64.191.10) in the
  21.    /tcl/docs directory or via the World Wide Web as
  22.    http://route.psg.com/tcl.html.
  23.  
  24.    Note that this FAQ deals with Tcl, not with Tk. For Tk Toolkit Q&As
  25.    see the FAQ posting by Thomas J. Accardo (tja@cpu.com) (see the
  26.    question below, entitled "Where can I get further info about Tcl" for
  27.    pointers to other Tcl FAQs). However, there is some inevitable
  28.    overlap. Some of the most commonly asked questions about usage of the
  29.    Tk widgets are due to mis-understandings of how the Tcl interpreter
  30.    works. These issues may still be addressed here. Also, some examples
  31.    of Tcl usage may involve the use of the Tk widgets.
  32.  
  33.    Questions and Answers about the use of non-Tk related extensions (such
  34.    as Extended Tcl and Expect, but not TkX, expectk, BLT, etc.) are also
  35.    appropriate here.
  36.  
  37.    The source of this document is maintained in HTML. It is then run
  38.    through a script (written in Tcl, of course) to automagically generate
  39.    the Index of Questions, and add the From and Subject lines to the text
  40.    version. The version available via the WWW will be updated whenever
  41.    there are changes, while the ASCII text version will be generated and
  42.    posted only once a month. Note also that the HTML version contains
  43.    many links that aren't listed in the text version.
  44.  
  45.    Last modified: Mon Apr 17 01:10:51 PDT 1995
  46.      _________________________________________________________________
  47.  
  48. Index of Questions:
  49.  
  50.   GENERAL INFORMATION:
  51.  
  52.      * Q.A1- Where can I get further info about Tcl?
  53.      * Q.A2- Where can I find help getting Tcl to work on my machine?
  54.      * Q.A3- How can I combine Tcl and C?
  55.      * Q.A4- How do I combine several extensions to provide all the
  56.        features I want?
  57.      * Q.A5- What about dynamic loading?
  58.      * Q.A6- How do I create a stand alone program in case Tcl isn't
  59.        installed?
  60.      * Q.A7- How do I make my script executable regardless of the
  61.        location of tclsh?
  62.      * Q.A8- Why isn't <some extension> part of the standard
  63.        distribution?
  64.  
  65.   PROGRAMMING RELATED QUESTIONS AND ANSWERS:
  66.  
  67.      * Q.B1- How can I create/use association lists or property lists?
  68.      * Q.B2- How can I generate a random number in Tcl?
  69.      * Q.B3- How can I call one proc with the multi parameter value
  70.        returned by another proc?
  71.      * Q.B4- How can I pass an array into a proc?
  72.      * Q.B5- How can I run an external command and read its output via a
  73.        pipe?
  74.      * Q.B6- How can I delete a procedure from within a script?
  75.      * Q.B7- How can I get more than 7 digits of double precision?
  76.      * Q.B8- How can I grab the command line when a non-built-in call is
  77.        made?
  78.      * Q.B9- How can I get or set an environment variable?
  79.      * Q.B10- How can I use numbers with leading zeroes?
  80.      * Q.B11- How can I find the command line arguments to my
  81.        application?
  82.      * Q.B12- I found a bug in the handling of comments!
  83.      * Q.B13- How can I input and output binary data?
  84.      * Q.B14- How can I trap signals, and perform other more Unix
  85.        specific functions?
  86.      * Q.B15- How can I do a double indirect? - Why doesn't $$var work?
  87.      * Q.B16- How can I get quoted strings to work the way I want?
  88.      * Q.B17- How can I share procedures between multiple tcl
  89.        applications?
  90.      * Q.B18- How can I get items inserted into a list?
  91.      * Q.B19- How can I perform a non-blocking read on a file identifier?
  92.      * Q.B20- How can I read and write from a pipe without locking up?
  93.      * Q.B21- How can I find what version I am running?
  94.      * Q.B22- How can I use variables to hold array names?
  95.  
  96.   EXPLANATION OF ERROR MESSAGES:
  97.  
  98.      * Q.C1- "not found" or "Command not found"
  99.      * Q.C2- invalid command name "}"
  100.      * Q.C3- missing close-brace
  101.      * Q.C4- X server insecure (must use xauth-style authorization)
  102.      * Q.C5- expected integer but got ...
  103.  
  104.   PLATFORM SPECIFIC AND PORTABILITY RELATED QUESTIONS:
  105.  
  106.      * Q.D1- How can I create shared Tcl/Tk libraries on AIX
  107.      * Q.D2- Has anyone gotten Tcl to compile under HP-UX?
  108.      * Q.D3- Has anyone gotten Tcl to compile under VMS?
  109.      * Q.D4- What does it take to get Tcl to compile under SCO Unix?
  110.      * Q.D5- Why do I get format and scan errors when I run tclTest?
  111.      * Q.D6- Why do I get lots of errors under Irix 4.0.1 when I run
  112.        tclTest?
  113.      * Q.D7- Does anyone else have problems with Tcl on a Cray?
  114.      * Q.D8- How do I install Tcl 7.1/Tk 3.4 on NeXTSTEP 3.1?
  115.      * Q.D9- Installing TCL7.1 on NeXT
  116.      * Q.D10- Installing TK3.4 on NEXTSTEP 3.1
  117.      * Q.D11- Why can't I print the draft of the Tcl/Tk book?
  118.      * Q.D12- Why am I getting errors on my SGI Indigo workstation?
  119.      * Q.D13- How do I build expect on Solaris 2.3?
  120.      * Q.D14- How do I port Tcl and Tk to a Sequent?
  121.      * Q.D15- How do I get around the symbol table full msg in AU/X 3.0?
  122.      * Q.D16- How do I compile Tcl on MS-DOS, MacOS, or other non-UNIX
  123.        system?
  124.      * Q.D17- How do I get Tcl to compile on my QNX system?
  125.  
  126.      _________________________________________________________________
  127.  
  128.   GENERAL INFORMATION:
  129.  
  130. ------------------
  131.  
  132. From: Tcl Q&A
  133. Subject: Q.A1- Where can I get further info about Tcl?
  134.  
  135.    The newsgroup comp.lang.tcl is for discussion of the Tcl language and
  136.    packages based on it. There are several FAQ documents related to Tcl
  137.    available from ftp.aud.alcatel.com in the /tcl/docs directory that
  138.    provide further information and pointers to yet more reading material,
  139.    both on-line and in print. They can also be accessed via the World
  140.    Wide Web:
  141.    http://www.cis.ohio-state.edu/hypertext/faq/usenet/tcl-faq/top.html
  142.  
  143.    Three other good starting points, if you are surfing the Web for
  144.    information, are: http://www.sco.com/Technology/tcl/Tcl.html
  145.    http://web.cs.ualberta.ca/~wade/HyperTcl/
  146.    http://playground.sun.com/~ouster/
  147.  
  148.    Of course, the source distribution itself includes a great deal of
  149.    documentation. The latest version is 7.3, with the 7.4b3 beta release
  150.    also available. Both can be obtained from:
  151.    ftp://ftp.cs.berkeley.edu/ucb/tcl/. 
  152.  
  153. ------------------
  154.  
  155. From: Tcl Q&A
  156. Subject: Q.A2- Where can I find help getting Tcl to work on my machine?
  157.  
  158.    Look in the Tcl distribution for the file called porting.notes. This
  159.    will contain a collection of notes that various people have provided
  160.    about porting Tcl to various machines and operating systems. There is
  161.    also a file called README which should be read FIRST - before doing
  162.    anything else with the code (this should always be one's first step
  163.    with any package).
  164.  
  165.    There are also several questions and answers related to building the
  166.    interpreter on various platforms at the end of this document. 
  167.  
  168. ------------------
  169.  
  170. From: Tcl Q&A
  171. Subject: Q.A3- How can I combine Tcl and C?
  172.  
  173.    Tcl was intended to be used along with C code. Because of this, there
  174.    are several ways to combine the two. Here is a list of some of them
  175.    (with man page references for further info):
  176.      * Adding Commands to Tcl (Tcl_CreateCommand)
  177.      * Command Traces (Tcl_CreateTrace)
  178.      * Variable Traces (Tcl_TraceVar)
  179.      * Getting/Setting Variables (Tcl_GetVar/Tcl_SetVar)
  180.      * Linking Variables (Tcl_LinkVar)
  181.      * Asynchronous Event Handlers (Tcl_AsyncCreate)
  182.      * Adding Functions to expr Command (Tcl_CreateMathFunc)
  183.      * Custom tclAppInit Routine (Tcl_AppInit)
  184.      * Custom main Routine (Tcl_Main)
  185.      * Via Pipes (open)
  186.      * exec Command (exec)
  187.  
  188.    The last two do not provide nearly the same level of integration as
  189.    those near the top of the list, but they are necessary if you do not
  190.    have access to the source code.
  191.  
  192.    There is plenty of documentation available that explains this in
  193.    further detail. See the TclCommandWriting man page, included with
  194.    Extended Tcl or available via the WWW at
  195.    http://psg.com/~joem/CmdWrite.html
  196.  
  197.    See also part two of Larry's Tcl FAQ and the Tcl Bibliography for
  198.    other references.
  199.  
  200.    In addition to all the ways possible with standard Tcl, several
  201.    extensions add others, notably via pseudo-ttys with expect, and via X
  202.    event, file event, timer, and idle callback handlers with Tk. Also
  203.    check out Embedded Tk, available from ftp://ftp.std.com/pub/drh/ 
  204.  
  205. ------------------
  206.  
  207. From: Tcl Q&A
  208. Subject: Q.A4- How do I combine several extensions to provide all the
  209.     features I want?
  210.  
  211.    The simple answer is to create a custom Tcl_AppInit function to call
  212.    the Init procedures for each of the desired extensions. This can be
  213.    done by copying the tclAppInit.c (tkAppInit.c for Tk apps) file from
  214.    Tcl source distribution, modifying it, and then linking your
  215.    Tcl_AppInit function with the Tcl library. For example, the standard
  216.    Tcl_AppInit looks like this:
  217.  
  218.     int
  219.     Tcl_AppInit(interp)
  220.         Tcl_Interp *interp; /* Interpreter for application. */
  221.     {
  222.         /* ... */
  223.  
  224.         if (Tcl_Init(interp) == TCL_ERROR) {
  225.             return TCL_ERROR;
  226.         }
  227.  
  228.         /* ... */
  229.     }
  230.  
  231.    In order to add the foo extension, you would add a call to the foo
  232.    init function, like this:
  233.  
  234.     int
  235.     Tcl_AppInit(interp)
  236.         Tcl_Interp *interp; /* Interpreter for application. */
  237.     {
  238.         /* ... */
  239.  
  240.         if (Tcl_Init(interp) == TCL_ERROR) {
  241.             return TCL_ERROR;
  242.         }
  243.  
  244.         if (Foo_Init(interp) == TCL_ERROR) {
  245.             return TCL_ERROR;
  246.         }
  247.  
  248.         /* ... */
  249.     }
  250.  
  251.    For more information, see the Tcl_AppInit man page and the
  252.    tclAppInit.c file.
  253.  
  254.    The more complete answer is that the simple answer doesn't always
  255.    work. Many extensions require more extensive modifications and the way
  256.    to combine them depends on the specific extensions involved.
  257.  
  258.    If you wish to include Extended Tcl, you should start with the
  259.    Tcl_AppInit function that comes with it. Also make sure when you link
  260.    the program that you include the Extended Tcl library before the
  261.    standard Tcl library, for example:
  262.  
  263.     cc -o mytclsh mytclXAppInit.c -ltclx -ltcl ...
  264.  
  265.    or for an interpreter including the Tk extensions:
  266.  
  267.     cc -o mywish mytkXAppInit.c -ltkx -ltk -ltclx -ltcl ...
  268.  
  269.    On the positive side, there are also several packages available that
  270.    can aid in combining extensions, such as Make-A-Wish, or extensions
  271.    that include configuration files for combining them with other popular
  272.    extensions. For example, several extensions written by Sven Delmas
  273.    allow you to specify options to configure to generate a Makefile that
  274.    will build an interpreter containing the specified extensions. See
  275.    part four of Larry Virden's FAQ for the location of these and other
  276.    packages. 
  277.  
  278. ------------------
  279.  
  280. From: Tcl Q&A
  281. Subject: Q.A5- What about dynamic loading?
  282.  
  283.    The issue of dynamic loading appears fairly often in comp.lang.tcl and
  284.    yes, the ideal method of combining extensions would be to use dynamic
  285.    loading, but the standard Tcl distribution does not currently support
  286.    it.
  287.  
  288.    The syntax of the load command has pretty much already been worked
  289.    out. It is just a matter of implementing it on a large number of
  290.    platforms (this is something that is definately platform dependent).
  291.  
  292.    Here is an excerpt from a message, dated 14 Jul 1993, written by John
  293.    Ousterhout on the subject:
  294.  
  295.      At the [1993 Tcl] workshop we decided to standardize on a simple Tcl
  296.      command interface for dynamic loading. The command syntax will be as
  297.      follows:
  298.  
  299.         load <file>
  300.  
  301.      where <file> is the name of a dynamically-loadable object file such
  302.      as libtcl.so. The syntax of these names may vary from system to
  303.      system according to local custom, but part of the name should be the
  304.      package prefix for the package, such as tcl in the above example.
  305.  
  306.      The load command must load the given object file, pick the package
  307.      prefix out of the file name, then invoke the procedure
  308.      <prefix>_Init, where <prefix> is the package prefix with the first
  309.      letter capitalized, e.g. Tcl_Init or Dp_Init or Tclx_Init. Each
  310.      loadable package must contain an initialization procedure that takes
  311.      a single argument that is a (Tcl_Interp *):
  312.  
  313.         int Dp_Init(Tcl_Interp *interp);
  314.  
  315.      The init procedure adds all of that package's Tcl commands into the
  316.      interpreter, plus performs any other package-specific
  317.      initialization. It returns a standard Tcl completion code and leaves
  318.      an error message or result value in the interpreter, which is
  319.      returned as the result of the load command.
  320.  
  321.    Implementations for certain platforms are already available, check the
  322.    software catalog (parts four and five of Larry Virden's FAQ) for
  323.    details (e.g. the Shells package) and Kevin Kenny's implementation
  324.    which is available from http://ce-toolkit.crd.ge.com/tcl/tcl.html. See
  325.    also the paper by Kevin Kenny from the 1994 Tcl workshop proceedings
  326.    available from
  327.    http://crdis1.ge.com/papers/gecrd/mtl/mdip/tcl94/00header.html.
  328.    Hopefully soon this will become part of the standard distribution. 
  329.  
  330. ------------------
  331.  
  332. From: Tcl Q&A
  333. Subject: Q.A6- How do I create a stand alone program in case Tcl isn't
  334.     installed?
  335.  
  336.    Earle Lowe (lowee@cpsc.ucalgary.ca) has replied that:
  337.  
  338.      If you want to create a stand-alone program that will run anywhere
  339.      regardless of the presence/absence of TCL/Tk, than you need to go
  340.      through some more work.
  341.  
  342.      Basically, this involves converting the TCL init files to C strings,
  343.      and then rather than calling Tcl_Init() and Tk_Init(), you call
  344.      Tcl_Eval() with the converted C strings as arguments.
  345.  
  346.      I suggest getting the wish_compiler package by Alexei Rodriguez
  347.      (alexei@cis.ufl.edu) from
  348.      ftp://ftp.aud.alcatel.com/tcl/code/wish_compiler.shar.gz 
  349.  
  350.      This package contains a tcl2c converter, and instructions as to its
  351.      use.
  352.  
  353.      With some Makefile magic, you can use using TCL/Tk as intended (as
  354.      an interpreted language using some version of wish) and when the
  355.      code works, you can create a stand-alone compiled program.
  356.  
  357.    Another option that is now available is "Embedded Tk". You can get it
  358.    from ftp://ftp.std.com/pub/drh/ 
  359.  
  360. ------------------
  361.  
  362. From: Tcl Q&A
  363. Subject: Q.A7- How do I make my script executable regardless of the
  364.     location of tclsh?
  365.  
  366.    There are several tricks you can use, but the most common is to make
  367.    use of the fact that, in Tcl, the backslash character works as a line
  368.    continuation indicator, even within comments. So instead of:
  369.  
  370.     #! /usr/local/bin/tclsh
  371.  
  372.     puts "Hello World"
  373.  
  374.    You could use:
  375.  
  376.     #! /bin/sh
  377.     # The next line is executed by /bin/sh, but not Tcl \
  378.       exec tclsh $0 ${1+"$@"}
  379.  
  380.     puts "Hello World"
  381.  
  382.    and the script will run regardless of where tclsh is located (as long
  383.    as it is in one of the directories in the user's PATH). 
  384.  
  385. ------------------
  386.  
  387. From: Tcl Q&A
  388. Subject: Q.A8- Why isn't <some extension> part of the standard
  389.     distribution?
  390.  
  391.    Often people ask why some language extension that they use often (in
  392.    fact, they may find it indispensible) isn't merged into the core
  393.    language.
  394.  
  395.    It must be remembered that a lot of people use Tcl on widely differing
  396.    systems and in vastly different ways. Also, Tcl was originally
  397.    intended as an embedded language that would provide the minimal
  398.    programming constructs and framework upon which a programmer could
  399.    base the scripting language for their application.
  400.  
  401.    Having said that, the core Tcl language has grown over the years. Some
  402.    of the added features have come from extensions written by others.
  403.    When the capabilities provided by extensions are deemed to be of
  404.    sufficient value to all users of Tcl, John has added them to the base
  405.    language. Some examples are associative arrays, the file I/O commands
  406.    (and file handles), and the unknown procedure, all of which appeared
  407.    in Extended Tcl before becoming part of standard Tcl. Tk 4.0 will
  408.    contain (and Tk4.0b3 does now contain) the equivalent functionality of
  409.    the addinput and photo widget extensions that were written by others
  410.    for Tcl 7.x/Tk 3.x.
  411.      _________________________________________________________________
  412.  
  413.   PROGRAMMING RELATED QUESTIONS AND ANSWERS:
  414.  
  415. ------------------
  416.  
  417. From: Tcl Q&A
  418. Subject: Q.B1- How can I create/use association lists or property lists?
  419.  
  420.    Use arrays or Extended Tcl keyed lists.
  421.  
  422.    For example, if you did a:
  423.  
  424.     keylset ttyFields ttyName tty1a
  425.     keylset ttyFields baudRate 57600
  426.     keylset ttyFields parity strip
  427.  
  428.    And then an echo $ttyFields, you'd get:
  429.  
  430.     {ttyName tty1a} {baudRate 57600} {parity strip}
  431.  
  432.    Or using arrays:
  433.  
  434.     set ttyFields(ttyName)  tty1a
  435.     set ttyFields(baudRate) 57600
  436.     set ttyFields(parity)   strip
  437.  
  438. ------------------
  439.  
  440. From: Tcl Q&A
  441. Subject: Q.B2- How can I generate a random number in Tcl?
  442.  
  443.    Extended Tcl includes a command named random that is an interface to
  444.    the random number generator in the system's standard C library.
  445.  
  446.    For example, to generate a random number between 0 and 9 inclusive:
  447.  
  448.     set random_number [random 10]
  449.  
  450.    It also allows you to specify a seed value.
  451.  
  452.    To get a value you can use as a seed, you might try one or a
  453.    combination of these (on Unix-like systems):
  454.  
  455.     [pid]
  456.     [file atime /dev/kmem]
  457.     [getclock]        (Extended Tcl only)
  458.  
  459.    Several pseudo-random number generator functions, written in straight
  460.    Tcl, have been posted to comp.lang.tcl, see Larry's tcl-faq/part4 for
  461.    a list.
  462.  
  463.    Here is one that is syntax compatible with the one in Extended Tcl,
  464.    but implemented in standard Tcl. The constants are from Don Libes. Be
  465.    aware that there is little checking for valid arguments.
  466.  
  467.     proc random {args} {
  468.         global RNG_seed
  469.  
  470.         set max 259200
  471.         set argcnt [llength $args]
  472.         if { $argcnt < 1 || $argcnt > 2 } {
  473.             error "wrong # args: random limit | seed ?seedval?"
  474.         }
  475.         if ![string compare [lindex $args 0] seed] {
  476.             if { $argcnt == 2 } {
  477.                 set RNG_seed [lindex $args 1]
  478.             } else {
  479.                 set RNG_seed [expr \
  480.                     ([pid]+[file atime /dev/kmem])%$max]
  481.             }
  482.             return
  483.         }
  484.         if ![info exists RNG_seed] {
  485.             set RNG_seed [expr ([pid]+[file atime /dev/kmem])%$max]
  486.         }
  487.         set RNG_seed [expr ($RNG_seed*7141+54773) % $max]
  488.         return [expr $RNG_seed % [lindex $args 0]]
  489.     }
  490.  
  491. ------------------
  492.  
  493. From: Tcl Q&A
  494. Subject: Q.B3- How can I call one proc with the multi parameter value
  495.     returned by another proc?
  496.  
  497.    Assuming y requires multiple args and x returns multiple words, use
  498.    Tcl's eval command:
  499.  
  500.     eval y [x]
  501.  
  502. ------------------
  503.  
  504. From: Tcl Q&A
  505. Subject: Q.B4- How can I pass an array into a proc?
  506.  
  507.    Use upvar rather than try to use global variables when possible. If
  508.    the function is event driven, you are forced to use global variables.
  509.  
  510.     # print elements of an array
  511.     proc show_array arrayName {
  512.         upvar $arrayName myArray
  513.  
  514.         foreach element [array names myArray] {
  515.            puts stdout "${arrayName}($element) =  $myArray($element)"
  516.         }
  517.     }
  518.  
  519.     set arval(0) zero
  520.     set arval(1) one
  521.     show_array arval
  522.  
  523.    To return an array from a procedures, just take the array name in as
  524.    an argument, as above. Any changes you make in the array will be made
  525.    in the parent's array as well.
  526.  
  527.    Extended Tcl introduces a concept called keyed lists which are arrays
  528.    made out of lists of key-value pairs and can be passed by value to
  529.    routines, over networks, etc. 
  530.  
  531. ------------------
  532.  
  533. From: Tcl Q&A
  534. Subject: Q.B5- How can I run an external command and read its output via a
  535.     pipe?
  536.  
  537.    For example, to grep a pattern out of a range of files, one might do:
  538.  
  539.    Karl Lehenbauer (karl@NeoSoft.com) writes:
  540.  
  541.     set files [glob /home/cole/stats/*]
  542.  
  543.     proc parseInfo { site } {
  544.        global files
  545.  
  546.     #
  547.     # site is chosen from a listbox earlier
  548.     #
  549.        set in [open [concat "|/usr/bin/grep $site $files"] r]
  550.  
  551.        while {[gets $in line]>-1} {
  552.           puts stderr $line
  553.        }
  554.        catch {close $in}
  555.     }
  556.  
  557.    One thing: the matching strings are not returned in directory order.
  558.  
  559.    But what if I want to check the return code AND use the output of the
  560.    command? Kevin B. Kenny (kennykb@dssv01.crd.ge.com) writes:
  561.  
  562.     if [catch {exec ls} data] {
  563.         # The exec got an error, and $errorCode has its termination status
  564.     } else {
  565.         # The exec succeeded
  566.     }
  567.     # In any case, `data' contains all the output from the child process.
  568.  
  569.    Note that Karl Lehenbauer (karl@NeoSoft.com) adds that errorCode will
  570.    be a list containing three elements, the string "CHILDSTATUS", the
  571.    process ID of the child, and the exit status of the child. 
  572.  
  573. ------------------
  574.  
  575. From: Tcl Q&A
  576. Subject: Q.B6- How can I delete a procedure from within a script?
  577.  
  578.    Rename the procedure to have no name, for example:
  579.  
  580.     rename procedureName ""
  581.  
  582. ------------------
  583.  
  584. From: Tcl Q&A
  585. Subject: Q.B7- How can I get more than 7 digits of double precision?
  586.  
  587.    In Tcl 7.x, set the global variable tcl_precision to a value in the
  588.    range 1-17. For example:
  589.  
  590.     % expr 4*atan(1)
  591.     3.14159
  592.     % set tcl_precision 0
  593.     can't set "tcl_precision": improper value for precision
  594.     % set tcl_precision 3
  595.     3
  596.     % expr 4*atan(1)
  597.     3.14
  598.     % set tcl_precision 16
  599.     16
  600.     % expr 4*atan(1)
  601.     3.141592653589793
  602.     % set tcl_precision 18
  603.     can't set "tcl_precision": improper value for precision
  604.  
  605.    In Tcl 6.x, you must modify the tclExpr.c module to use %lf instead of
  606.    %g. 
  607.  
  608. ------------------
  609.  
  610. From: Tcl Q&A
  611. Subject: Q.B8- How can I grab the command line when a non-built-in call is
  612.     made?
  613.  
  614.    The procedure unknown is called automatically with arguments
  615.    containing the command and its arguments for any command that couldn't
  616.    be found. In fact, Tcl and Extended Tcl use this feature to provide
  617.    demand loaded commands, and even entire libraries. Also, when using
  618.    the "tclsh" or "tcl" shells interactively, the unknown procedure
  619.    enables the shell to run external programs (i.e. without typing "exec"
  620.    first).
  621.  
  622.    So by modifying the unknown procedure you can provide your own
  623.    extended functionality, or even remove the demand loading capability
  624.    if you so desire. 
  625.  
  626. ------------------
  627.  
  628. From: Tcl Q&A
  629. Subject: Q.B9- How can I get or set an environment variable?
  630.  
  631.    By using something like the following.
  632.  
  633.     set olddisplay $env(DISPLAY)
  634.     set env(DISPLAY) unix:0
  635.  
  636.    Thanks to Joel Fine (joel@cs.berkeley.edu) for the answer.
  637.  
  638.    You can also check if an environment variable exists, like this:
  639.  
  640.     if [info exists env(VARNAME)] {
  641.         # okay, it's there use it
  642.         set value $env(VARNAME)
  643.     } else {
  644.         # the environment var isn't set, use a default
  645.         set value "the default value"
  646.     }
  647.  
  648. ------------------
  649.  
  650. From: Tcl Q&A
  651. Subject: Q.B10- How can I use numbers with leading zeroes?
  652.  
  653.    In Tcl, numbers that start with a zero are interpreted as octal values
  654.    (or hexadecimal, if the zero is immediately followed by an 'x').
  655.    Often, this is a useful feature, but there are some problems:
  656.      * What if the number has invalid octal (hexadecimal) digits?
  657.  
  658.        Prior to Tcl 7.4b3, the interpreter would try to interpret a
  659.        number such as 08 as a floating point value. Starting with 7.4b3,
  660.        the interpreter generates an error message when presented with
  661.        such a value.
  662.      * What if you want the value interpreted as a decimal number (as if
  663.        the leading zeros weren't there)?
  664.  
  665.        You have to strip off the zeros. Here are two implementations of a
  666.        function "stripzeros":
  667.  
  668.     proc stripzeros {value} {
  669.         regsub ^0+(.+) $value \\1 retval
  670.         return $retval
  671.     }
  672.    or
  673.  
  674.     proc stripzeros {value} {
  675.         set retval [string trimleft $value 0]
  676.         if ![string length $retval] {
  677.             return 0
  678.         }
  679.         return $retval
  680.     }
  681.    Then, whenever you are passing a value to a command that requires an
  682.        integer value, and there is the possibility that the value has a
  683.        leading zero, just pass it through this function first, i.e.
  684.        instead of:
  685.  
  686.     set dayofweek [expr $days%7]
  687.    use:
  688.  
  689.     set dayofweek [expr [stripzeros $days]%7]
  690.  
  691. ------------------
  692.  
  693. From: Tcl Q&A
  694. Subject: Q.B11- How can I find the command line arguments to my
  695.     application?
  696.  
  697.    The program name is assigned to the global variable argv0 and any
  698.    arguments to it are placed in the global variable argv as a list. The
  699.    variable argc is set to the number of elements in the list argv. As an
  700.    example:
  701.  
  702.     #! /usr/local/bin/tclsh
  703.  
  704.     if { $argc != 2 } {
  705.         puts stderr "$argv0: Usage: $argv0 <infile> <outfile>"
  706.         exit 1
  707.     }
  708.  
  709.     set infile  [lindex $argv 0]
  710.     set outfile [lindex $argv 1]
  711.  
  712. ------------------
  713.  
  714. From: Tcl Q&A
  715. Subject: Q.B12- I found a bug in the handling of comments!
  716.  
  717.    Sometimes people find that Tcl behaves differently than they expect
  718.    (often because of the way some other language acts in a similar
  719.    situation). They then think this unexpected behavior is a bug.
  720.    Probably the most common occurance of this is in regard to comments.
  721.  
  722.    In Tcl, everything passed to the parser must have proper list
  723.    structure, even comments (and yes comments are passed to the parser,
  724.    unlike in some languages where they are stripped at an earlier stage).
  725.    Generally, this means you need to make sure your braces are evenly
  726.    matched, even though they may be on a line that is commented out.
  727.  
  728.    So, for example, you have an if statement that tests a certain
  729.    condition, but you want to try testing a different condition. You
  730.    comment out the old condition and type a new if statement. This code
  731.    will cause an error that there is a missing close-brace:
  732.  
  733.     ## WRONG
  734.     if { $newflag } {
  735.     # if { $oldflag } {
  736.         puts hello
  737.     }
  738.  
  739.    In this case, you have to balance the braces, for example:
  740.  
  741.     ## CORRECT
  742.     if { $newflag } {
  743.     # if { $oldflag } {
  744.         puts hello
  745.     # }
  746.     }
  747.  
  748.    Another interesting point about comments in Tcl is that the line
  749.    continuation mechanism still applies, so:
  750.  
  751.     # This is a comment line that ends with a backslash \
  752.       and this line is still part of the comment
  753.  
  754. ------------------
  755.  
  756. From: Tcl Q&A
  757. Subject: Q.B13- How can I input and output binary data?
  758.  
  759.    With Extended Tcl you can safely do stuff like:
  760.  
  761.     set infp [open "|compress -dc $fileName"]
  762.     set outfp [open "|gzip -c $newFileName" w]
  763.  
  764.     copyfile $infp $outfp
  765.  
  766.    Thanks to Karl Lehenbauer (karl@NeoSoft.com) for the code example.
  767.  
  768.    A method of handling binary data one character at a time using
  769.    standard Tcl can be found in:
  770.    ftp.aud.alcatel.com:/tcl/code/binary-io-hack.shar.gz
  771.  
  772.    There are also two different extensions available that enable the
  773.    handling of binary data: tclbin and BinarIO. The former is better for
  774.    handling structured data, while the latter works better for binary
  775.    data streams. 
  776.  
  777. ------------------
  778.  
  779. From: Tcl Q&A
  780. Subject: Q.B14- How can I trap signals, and perform other more Unix
  781.     specific functions?
  782.  
  783.    Extended Tcl offers many of these types of functions. For instance,
  784.    extended Tcl has the signal command:
  785.  
  786.      signal action siglist [command]
  787.  
  788.      where action is one of "default", "ignore", "error", "trap", "get",
  789.      plus the POSIX "block" and "unblock" actions (available only on
  790.      POSIX systems, of course). Siglist is a list of either the symbolic
  791.      or numeric Unix signal (the SIG prefix is optional). Command is your
  792.      error handler (or a simple {puts stdout "Don't press *that* key!"}
  793.      :-)
  794.  
  795.    trap does what you expect, and I find error and get to be extremely
  796.    useful in interactive programs which demand keyboard traversal.
  797.  
  798.    Extended Tcl also has things like fork, etc.
  799.  
  800.    Answer by Brad Morrison (brad@NeoSoft.com). 
  801.  
  802. ------------------
  803.  
  804. From: Tcl Q&A
  805. Subject: Q.B15- How can I do a double indirect? - Why doesn't $$var work?
  806.  
  807.    There is one and only one level of substitution possible with every
  808.    pass through the interpreter. Also, when doing variable substitution,
  809.    the interpreter finds the dollar sign and then takes everything
  810.    following it up until the next invalid character (where invalid is
  811.    defined as anything other than a letter, digit, or underscore) as the
  812.    name of the variable - well, that is, unless it finds array notation
  813.    or the ${varname} form.
  814.  
  815.    In the case of $$var, the character after the first dollar sign is an
  816.    invalid character (another dollar sign), so there is no variable name
  817.    and variable substitution is not performed (the dollar sign is left as
  818.    is) and scanning starts again for any dollar signs and a following
  819.    variable name. It is immediately found at that second dollar sign, the
  820.    substitution is performed, and scanning for dollar signs resumes with
  821.    whatever was after the variable name. Since there isn't anything else,
  822.    substition is done for this pass through the interpreter (remember
  823.    it's only done once).
  824.  
  825.    The eval command runs it's arguments through the interpreter, so you
  826.    could use eval to cause a second pass through the interpreter, and
  827.    thus, have $$var work:
  828.  
  829.     % set a 5
  830.     5
  831.     % set var a
  832.     a
  833.     % puts $$var              ;# This doesn't work
  834.     $a
  835.     % eval puts $$var         ;# This does  - but it's dangerous
  836.     5
  837.  
  838.    However, if the contents of var contain any special characters (e.g.
  839.    whitespace, semicolon) you'll run into problems.
  840.  
  841.    A better method is to take advantage of the behaviour of the set
  842.    command when given only one argument, and combine command substitution
  843.    with variable substitution:
  844.  
  845.     % puts [set $var]         ;# This works safely
  846.     5
  847.  
  848.    or, in fact, you could use just command substitution (which is
  849.    performed once for each [ ] pair):
  850.  
  851.     % puts [set [set var]]    ;# as does this
  852.     5
  853.  
  854. ------------------
  855.  
  856. From: Tcl Q&A
  857. Subject: Q.B16- How can I get quoted strings to work the way I want?
  858.  
  859.    A long article dealing with the issues can be found at
  860.    ftp://ftp.aud.alcatel.com/tcl/docs/README.programmer.gz
  861.  
  862.    Here are some short answers:
  863.  
  864.    Q. I'm trying to build up a command for later execution but am having
  865.    trouble with variable values that include whitespace or special
  866.    characters.
  867.  
  868.    A. The safest way to build up commands is to use the list command so
  869.    that you can keep track of the list structure. Avoid using double
  870.    quotes because you can end up with an extra trip through the
  871.    evaluator. We'll illustrate this with a command to create a button
  872.    that prints out the label on the button when you click it.
  873.  
  874.      Wrong answer #1:
  875.  
  876.     button $myname -text $label -command "puts stdout $label"
  877.  
  878.      Why? because if $label has whitespace then the puts command will be
  879.      passed the wrong number of arguments. If $label has $ or [ ]
  880.      characters, they will be interpreted instead of printed.
  881.      Good answer #2:
  882.  
  883.     button $myname -text $label -command [list puts stdout $label]
  884.  
  885.      Why? because list will properly quote the value of $label
  886.  
  887.    Q. I'm trying to build up a command for later execution but am having
  888.    trouble getting some variables to evaluate now, and some to evaluate
  889.    later when the command is run.
  890.  
  891.    A. The cleanest way to do this is to define a procedure that hides the
  892.    use of the variables at run time, and then build up a call to that
  893.    procedure using the list command as described previously. (You can
  894.    even define the procedure on the fly. It will have global scope even
  895.    it if is created within another procedure.)
  896.  
  897.      Wrong answer #1:
  898.  
  899.     button $myname -text $label -command \
  900.         [list puts stdout $ArrayOfDynamicStuff($label)]
  901.  
  902.      Why? The array value will be substituted when the button is created,
  903.      not later on when the button is clicked. Also, note that the command
  904.      is executed at the global scope, so it is not necessary to include a
  905.      "global ArrayOfDynamicStuff" in the command.
  906.      Wrong answer #2 (backquotes and list):
  907.  
  908.     button $myname -text $label -command \
  909.         [list puts stdout \$ArrayOfDynamicStuff($label)]
  910.  
  911.      Why? Here the list command and the backquote of $ are fighting with
  912.      each other. The command ends up being something like:
  913.  
  914.     puts stdout {$ArrayOfDynamicStuff(foo)}
  915.  
  916.      which prevents the substitution of the value of the array element.
  917.      Dubious answer #3 (backquotes and double-quotes):
  918.  
  919.     button $myname -text $label -command \
  920.         "puts stdout \$ArrayOfDynamicStuff($label)"
  921.  
  922.      Why? This only works if the value of $label has no special
  923.      characters or whitespace.
  924.      Clean answer #4 (proc):
  925.  
  926.     proc doit { i } {
  927.         global ArrayOfDynamicStuff
  928.         puts stdout $ArrayOfDynamicStuff($i)
  929.     }
  930.     button $myname -text $label -command [list doit $label]
  931.  
  932.      Why? Using little TCL procs for your button commands is a good habit
  933.      because it eliminates most needs for fancy quoting, and it makes it
  934.      easier to tweak the button command later on.
  935.  
  936.    Q. I'm trying to pass along a variable number of args to another
  937.    procedure but I'm having trouble getting the $args to expand right.
  938.  
  939.    A. Avoid using eval and double quotes because that results in an extra
  940.    trip through the interpreter. The eval command will do a concat of its
  941.    arguments if there are more than one, so that pretty much eliminates
  942.    the need to group things with double quotes. Let's extend the button
  943.    example:
  944.  
  945.      Wrong answer #1:
  946.  
  947.     proc mybutton { myname label args } {
  948.         button $myname -text $label -command [list puts stdout $label] $args
  949.     }
  950.  
  951.      Why? All the extra arguments to mybutton are grouped into one list
  952.      element that is but into the value of $args. However, the button
  953.      command expects to see individual arguments, not a sub-list.
  954.      Wrong answer #2:
  955.  
  956.     proc mybutton { myname label args } {
  957.         eval "button $myname -text $label -command [list puts stdout $label] $a
  958. rgs"
  959.     }
  960.  
  961.      Why? The double quotes allow expansion of $label as well as $args,
  962.      so if $label has any whitespace, the button command will be
  963.      malformed
  964.      Good answer #3:
  965.  
  966.     proc mybutton { myname label args } {
  967.         set cmd {button $myname -text $label -command [list puts stdout $label]
  968. }
  969.         eval $cmd $args
  970.     }
  971.  
  972.      Why? Eval will first concatenate its two arguments and then run the
  973.      result through the interpreter. Think of this as stripping off the
  974.      outer curly braces from $cmd and $arg and making a single list with
  975.      all the elements of both. $label will be evaluated exactly once, so
  976.      the puts command will remain good, and whatever went into args will
  977.      also be processed exactly one time.
  978.  
  979.    Q. Why do I get a syntax error in an if/while/for statement?
  980.  
  981.    A. You may have written something like
  982.  
  983.     wish: set foo bar
  984.     wish: if {$foo == bar} {puts stdout bar}
  985.     syntax error in expression "$foo == bar"
  986.  
  987.    in which bar is interpreted as neither a string nor a variable, since
  988.    strings as operands in expressions MUST be surrounded by double quotes
  989.    or braces.
  990.  
  991.    Change to
  992.  
  993.     wish: if {$foo == "bar"} {puts stdout bar}
  994.  
  995.    or
  996.  
  997.     wish: if {$foo == {bar}} {puts stdout bar}
  998.  
  999.    always in expressions, depending on if you want expansion performed or
  1000.    not.
  1001.  
  1002.    Contributed by Jesper Blommaskog (d9jesper@dtek.chalmers.se). 
  1003.  
  1004. ------------------
  1005.  
  1006. From: Tcl Q&A
  1007. Subject: Q.B17- How can I share procedures between multiple tcl
  1008.     applications?
  1009.  
  1010.    Rather than sourcing the files explicitly, build a tcl library:
  1011.  
  1012.    Step 1. Put the files in a common directory
  1013.  
  1014.    Step 2. Build the tclIndex for the "library". I use a Makefile with a
  1015.    convention like:
  1016.  
  1017.     install.index:
  1018.         (cd ${DESTDIR}/tclscripts/lib; \
  1019.         echo 'source /usr/local/lib/tcl/init.tcl;\
  1020.         auto_mkindex . *.tk' | tcl ; exit 0)
  1021.  
  1022.    Step 3. Modify your tcl scripts to reference the library:
  1023.  
  1024.    e.g.:
  1025.  
  1026.     # local additions
  1027.     lappend auto_path /usr/local/lib/tcl_local $env(RDS_TCL_SCRIPTS)/lib
  1028.  
  1029.    Now, as soon as your script tried to reference a procedure in the
  1030.    library, the "unknown" command autoloads the procedure for you.
  1031.  
  1032.    Contributed by Joe VanAndel (vanandel@ncar.ucar.edu). 
  1033.  
  1034. ------------------
  1035.  
  1036. From: Tcl Q&A
  1037. Subject: Q.B18- How can I get items inserted into a list?
  1038.  
  1039.    A user asked why
  1040.  
  1041.     linsert $list 0 ..
  1042.  
  1043.    did not result in .. being inserted into list.
  1044.  
  1045.    Jesper Blommaskog (d9jesper@dtek.chalmers.se) replied:
  1046.  
  1047.    When doing list operations other than lappend, you must save the
  1048.    returned value. This applies to list, lindex, lrange, and lreplace at
  1049.    least.
  1050.  
  1051.    In this example, you would perhaps want to do something like:
  1052.  
  1053.     set list [ linsert $list 0 .. ]
  1054.  
  1055. ------------------
  1056.  
  1057. From: Tcl Q&A
  1058. Subject: Q.B19- How can I perform a non-blocking read on a file
  1059.     identifier?
  1060.  
  1061.    From Frank Smith (frank@arraysystems.nstn.ns.ca) we are told that if
  1062.    you have Extended Tcl, you can
  1063.  
  1064.     read $fileId [fstat $fileId size]
  1065.  
  1066.    This will read only the number of bytes currently available on fileId
  1067.    and consequently will not block. 
  1068.  
  1069. ------------------
  1070.  
  1071. From: Tcl Q&A
  1072. Subject: Q.B20- How can I read and write from a pipe without locking up?
  1073.  
  1074.    The stdio package has an optimization for speed that buffers
  1075.    characters so that you can avoid un-necessary system calls. This isn't
  1076.    very good for interactive use so stdio changes it's behaviour if the
  1077.    file is a terminal. When you write to a pipe you are not writing to a
  1078.    terminal and so your output is buffered, similarly when the program at
  1079.    the other end of the pipe writes its response it is also buffered. The
  1080.    end result is the programs at both end of the pipe stall waiting for
  1081.    input. It is possible to force the buffers to be written using flush
  1082.    in Tcl and fflush() in C, often though, you don't have control over
  1083.    the program at the other end of the pipeline and in that case your
  1084.    only solution is to use a pseudo-teletype (pty). Unfortunately this
  1085.    isn't all that easy.
  1086.  
  1087.    While this isn't directly supported in Tcl, the spawn command in
  1088.    expect opens a pty and starts a command. 
  1089.  
  1090. ------------------
  1091.  
  1092. From: Tcl Q&A
  1093. Subject: Q.B21- How can I find what version I am running?
  1094.  
  1095.    Well, there is no one answer to this. Tcl itself will tell you it's
  1096.    version if you type:
  1097.  
  1098.     info tclversion
  1099.  
  1100.    On the other hand, to get the Tk version, you must use:
  1101.  
  1102.     puts $tk_version
  1103.  
  1104.    Other extensions use other means (for example, Extended Tcl uses
  1105.    "infox version" to return it's version number). 
  1106.  
  1107. ------------------
  1108.  
  1109. From: Tcl Q&A
  1110. Subject: Q.B22- How can I use variables to hold array names?
  1111.  
  1112.    Eric Bleeker (ericbl@paramount.nikhefk.nikhef.nl) has written:
  1113.  
  1114.      You may have written something like:
  1115.  
  1116.     % set foo "bar baz"
  1117.     bar baz
  1118.     % foreach aap $foo {
  1119.         set $aap(1) "something"
  1120.     }
  1121.     can't read "aap(1)": variable isn't array
  1122.  
  1123.      This means Tcl tries to substitute the array element aap(1) which
  1124.      doesn't exist. To fix this use:
  1125.  
  1126.     % foreach aap $foo {
  1127.         set [set aap](1) "something"
  1128.     }
  1129.  
  1130.      In this case two arrays bar and baz are created.
  1131.  
  1132.    An alternative format is:
  1133.  
  1134.     % foreach aap $foo {
  1135.         set ${aap}(1) "something"
  1136.     }
  1137.  
  1138.      _________________________________________________________________
  1139.  
  1140.   EXPLANATION OF ERROR MESSAGES:
  1141.  
  1142.    This section lists some error messages and some possible (and
  1143.    non-obvious) reasons why you may be getting them. 
  1144.  
  1145. ------------------
  1146.  
  1147. From: Tcl Q&A
  1148. Subject: Q.C1- "not found" or "Command not found"
  1149.  
  1150.    This error message comes from your shell, not Tcl. The script probably
  1151.    starts with a #! that is followed by a path to the Tcl interpreter
  1152.    that is too long for your system. Many Unix systems are limited to 32
  1153.    characters (including the #!) in this regard. So, something like this
  1154.    will fail:
  1155.  
  1156.     #! /usr/home/homedir/very/long/path/tclsh
  1157.  
  1158.     # rest of script
  1159.  
  1160.    You can either shorten the path by moving the tclsh executable to a
  1161.    different directory or by using symbolic links. Another option is to
  1162.    not specify the path at all. See the question "How do I make my script
  1163.    executable regardless of the location of tclsh?" for an example of
  1164.    how to do this. 
  1165.  
  1166. ------------------
  1167.  
  1168. From: Tcl Q&A
  1169. Subject: Q.C2- invalid command name "}"
  1170.  
  1171.    You have probably commented out a line that ends with an open curly
  1172.    brace. See Question B12 for more info. 
  1173.  
  1174. ------------------
  1175.  
  1176. From: Tcl Q&A
  1177. Subject: Q.C3- missing close-brace
  1178.  
  1179.    Your braces aren't balanced. Again, one likely, though perhaps
  1180.    non-obvious, reason is improperly commented lines. See Question B12. 
  1181.  
  1182. ------------------
  1183.  
  1184. From: Tcl Q&A
  1185. Subject: Q.C4- X server insecure (must use xauth-style authorization)
  1186.  
  1187.    Tk requires you to have a secure X server before you can use the send
  1188.    command. See the question 2.A.7 "How can I get Tk 3.3 to even start -
  1189.    I get security error messages." in Thomas Accardo's Tk Toolkit Usage
  1190.    FAQ as well as http://ce-toolkit.crd.ge.com/tkxauth/ for instructions
  1191.    on how to make your server secure. 
  1192.  
  1193. ------------------
  1194.  
  1195. From: Tcl Q&A
  1196. Subject: Q.C5- expected integer but got ...
  1197.  
  1198.    This error occurs when trying to perform some mathematical operation
  1199.    that requires an integer value, but given a non-integer value. While
  1200.    this is pretty obvious when the value supplied is a floating point
  1201.    value or an alphabetic string, this error can be confusing when the
  1202.    value is something that may look like a valid integer. Specifically
  1203.    numbers that have leading zeros. See Question B10 for an explanation.
  1204.  
  1205.      _________________________________________________________________
  1206.  
  1207.   PLATFORM SPECIFIC AND PORTABILITY RELATED QUESTIONS:
  1208.  
  1209. ------------------
  1210.  
  1211. From: Tcl Q&A
  1212. Subject: Q.D1- How can I create shared Tcl/Tk libraries on AIX
  1213.  
  1214.    Dov Grobgeld (dov@menora.weizmann.ac.il) provided info on creating Tcl
  1215.    and Tk shared libraries under AIX 3.1.5:
  1216.  
  1217.      For Tcl:
  1218.  
  1219.     cc -o tkshar.o *.o -bE:tclshar.exp -bM:SRE -berok -lX11 -lm
  1220.     ar r libtclshr tclshar.o
  1221.  
  1222.      For Tk:
  1223.  
  1224.     cc -o tkshar.o *.o -bE:tkshar.exp -bM:SRE -berok -Ltcl -lX11 -lm -ltclshr
  1225.     ar r libtkshr tkshar.o
  1226.  
  1227.      where tckshar.exp and tkshar.exp had lists of the external
  1228.      functions.
  1229.  
  1230.      There are also problems with fonts on AIX and the IBM. A patch is
  1231.      needed from IBM to fix the X server so that fonts are working
  1232.  
  1233. ------------------
  1234.  
  1235. From: Tcl Q&A
  1236. Subject: Q.D2- Has anyone gotten Tcl to compile under HP-UX?
  1237.  
  1238.    See the porting notes. Also, be aware that there have been some
  1239.    reports of Configure assuming that you should use the compatibility
  1240.    version of opendir() and that you have no dirent.h . This causes
  1241.    glob-ing to fail, as well as TclX's readdir, etc.
  1242.  
  1243.    Changing tcl7.3 to remove the opendir compatibility file and removing
  1244.    the -DNO_DIRENT, -DUSE_DIRENT2 fixed it all up. 
  1245.  
  1246. ------------------
  1247.  
  1248. From: Tcl Q&A
  1249. Subject: Q.D3- Has anyone gotten Tcl to compile under VMS?
  1250.  
  1251.    Information from John Kimball (jkimball@src.honeywell.com) on May 4,
  1252.    1993 was that he had gotten Tcl 6.7 and Tk 3.2 ported to VMS 5.5. See
  1253.    the catalog for the file information. 
  1254.  
  1255. ------------------
  1256.  
  1257. From: Tcl Q&A
  1258. Subject: Q.D4- What does it take to get Tcl to compile under SCO Unix?
  1259.  
  1260.    Add a "#undef select" to tkEvent.c, and remove the reference to
  1261.    TK_EXCEPTION around line 460 of main.c.
  1262.  
  1263.    Tk uses its own scheme for allocating the border colors for its 3D
  1264.    widgets, which causes problems when running TK on a system with
  1265.    "PseudoColor" display class, and a 16-cell colormap.
  1266.  
  1267.    If you can't go to eight bitplanes, you can instead start the server
  1268.    with a "-static" (Xsco) or "-analog" (Xsight) option, making the
  1269.    display class become "StaticColor". This makes the entire colormap
  1270.    read-only, and it will return the color that most closely maps to the
  1271.    desired color as possible.
  1272.  
  1273.    This information is from Keith Amann (Keith_Amann@stortek.com). 
  1274.  
  1275. ------------------
  1276.  
  1277. From: Tcl Q&A
  1278. Subject: Q.D5- Why do I get format and scan errors when I run tclTest?
  1279.  
  1280.    That's a problem (scanf/printf) many systems seem to have. Don't worry
  1281.    too much about it - just don't use these 'advanced' features. If
  1282.    you're hacking C, you'll have the same problems.
  1283.  
  1284.    For instance, printf("%Ng", double_value) and strtod("+",&terminal)
  1285.    produce incorrect results. 
  1286.  
  1287. ------------------
  1288.  
  1289. From: Tcl Q&A
  1290. Subject: Q.D6- Why do I get lots of errors under Irix 4.0.1 when I run
  1291.     tclTest?
  1292.  
  1293.    There's a bug in the 4.0.1 optimizer that's fixed in 4.0.2. Compile
  1294.    tclVar.c using -O0 (no optimization). 
  1295.  
  1296. ------------------
  1297.  
  1298. From: Tcl Q&A
  1299. Subject: Q.D7- Does anyone else have problems with Tcl on a Cray?
  1300.  
  1301.    See the porting notes for a set of changes mentioned. Also, Booker C.
  1302.    Bense (benseb@grumpy.sdsc.edu) reports that version 3.0.1.6 has some
  1303.    real problems with char pointers, causing Tcl to crash. Using version
  1304.    3.0.2.1, things are much better, except for a minor formatting problem
  1305.    and serious problems with scan. 
  1306.  
  1307. ------------------
  1308.  
  1309. From: Tcl Q&A
  1310. Subject: Q.D8- How do I install Tcl 7.1/Tk 3.4 on NeXTSTEP 3.1?
  1311.  
  1312.    I have indicated in the past that this particular question seems to
  1313.    generate controversy - I have replaced previous explanations with the
  1314.    latest msg from someone who sounds authoritative...
  1315.  
  1316.    From: Robert Nicholson (robert@steffi.demon.co.uk)
  1317.  
  1318.      This is for TCL7.1 and TK3.4
  1319.  
  1320.      This is a variation on Thomas Funke's entry. 
  1321.  
  1322. ------------------
  1323.  
  1324. From: Tcl Q&A
  1325. Subject: Q.D9- Installing TCL7.1 on NeXT
  1326.  
  1327.      To install tcl7.1 on NeXTSTEP 3.1 you must:
  1328.      * run configure with predefined CPP:
  1329.        type "sh" to run a Bourne shell. then type
  1330.  
  1331.     CPP='cc -E' ./configure
  1332.      * edit Makefile:
  1333.        add tmpnam.o to COMPAT_OBJS:
  1334.  
  1335.   COMPAT_OBJS =      getcwd.o waitpid.o strtod.o tmpnam.o
  1336.  
  1337.      At this point you probably want to rename the all calls to strtod
  1338.      and tmpnam to something else in order to distinguish them from those
  1339.      that are supplied in the NeXT libraries libsys_a.a. You can do this
  1340.      by adding the following line to AC_FLAGS
  1341.  
  1342.     -Dstrtod=newstrtod -Dtmpnam=newtmpnam
  1343.  
  1344.      and renaming the names of the definitions in the appropriate
  1345.      compat/*.c files.
  1346.  
  1347.      To check everything is working correctly open a tclsh
  1348.  
  1349.     % expr {"0" == "+"}
  1350.     0
  1351.  
  1352.      Using the wrong strtod function will cause this test to return 1
  1353.      which is a serious error. Ignore the precision errors. 
  1354.  
  1355. ------------------
  1356.  
  1357. From: Tcl Q&A
  1358. Subject: Q.D10- Installing TK3.4 on NEXTSTEP 3.1
  1359.  
  1360.      There is a call to strtod in TK3.4 so you should link against
  1361.      ../tcl-7.1/compat/strtod.o and apply the -Dstrtod=newstrtod to
  1362.      AC_FLAGS in Tk also.
  1363.  
  1364.      Note:Tk's raise test will fail when running the tvtwm window
  1365.      manager. Changing to either twm or even better fvwm ensures that
  1366.      this test will succeed.
  1367.  
  1368. ------------------
  1369.  
  1370. From: Tcl Q&A
  1371. Subject: Q.D11- Why can't I print the draft of the Tcl/Tk book?
  1372.  
  1373.    From John Ousterhout (John.Ousterhout@Eng.Sun.COM):
  1374.  
  1375.    Here's my form letter that seems to explain most of the problems
  1376.    people have had printing parts of the book:
  1377.  
  1378.    Some old versions of the Transcript spooler software cannot properly
  1379.    handle encapsulated Postscript files within another Postscript file
  1380.    when they do page reversal. They tend to garble the page structure of
  1381.    the file, causing an error at the point of the first EPS file. Part II
  1382.    of the Tcl book has lots of EPS files embedded in it, one for each
  1383.    screen dump. If your printer cannot print this file I suggest checking
  1384.    to see if page reversal is enabled for your printer. If so, try asking
  1385.    your local system wizard to disable it for you; this should allow the
  1386.    file to print. Or, find some other way to dump the Postscript file
  1387.    directly to the printer without going through the spooling software
  1388.    (e.g. perhaps you can simply cat it to the printer's serial port).
  1389.  
  1390.    Others have suggested:
  1391.  
  1392.    The embedded pictures have CR as the line separator instead of LF and
  1393.    this may be causing the problem. Try translating them to LFs ...
  1394.  
  1395.     tr '\015' '\012' <book.p2.ps >fixedbook.p2.ps
  1396.  
  1397.    and:
  1398.  
  1399.    This is not the original poster's problem but in countries using A4
  1400.    paper and on a particular printer, the Dataproducts LZR1260E, the
  1401.    frame size causes the printing to be stretched vertically. This
  1402.    happens with other Framemaker generated documents by the way. A PS
  1403.    interpreter bug no doubt. The fix is to edit the dimensions for A4
  1404.    paper. This shell script does both fixes.
  1405.  
  1406.     #!/bin/sh
  1407.     cat $1 | tr '\015' '\012' | sed '/FMDOCUMENT$/s/612 792/595 842/'
  1408.  
  1409. ------------------
  1410.  
  1411. From: Tcl Q&A
  1412. Subject: Q.D12- Why am I getting errors on my SGI Indigo workstation?
  1413.  
  1414.    From Gordon Lack (gml4410@ggr.co.uk) we are told that the SGI c
  1415.    compiler has some bugs with variable arguments.
  1416.  
  1417.    tclVar.c must be compiled with -O0 at IRIX C 4.0.1 because of a
  1418.    compiler bug with varargs.
  1419.  
  1420.    Done by placing specific rule into Makefile.
  1421.  
  1422.     # GGR SG needs -O0 for varargs at 4.0.1
  1423.  
  1424.     CC_SWITCHES0 =  -O0 -I. -I${SRC_DIR} ${AC_FLAGS} ${MATH_FLAGS} \
  1425.           ${GENERIC_FLAGS} ${PROTO_FLAGS} ${MEM_DEBUG_FLAGS} \
  1426.           -DTCL_LIBRARY=\"${TCL_LIBRARY}\"
  1427.  
  1428.     tclVar.o: tclVar.c
  1429.           $(CC) -c $(CC_SWITCHES0) $<
  1430.  
  1431.    Peter Neelin (neelin@pet.mni.mcgill.ca) also noted that:
  1432.  
  1433.    I get tclX 7.3a to compile on an SGI (irix 4.0.5) with the following
  1434.    changes to the Config.mk file:
  1435.  
  1436.     71c71
  1437.     < CFLAGS=-cckr -D__GNU_LIBRARY__
  1438.     ---
  1439.     > #CFLAGS=
  1440.     106,107c106,107
  1441.     < TCL_PLUS_BUILD=TCL_PLUS
  1442.     < CCPLUS=g++
  1443.     ---
  1444.     > #TCL_PLUS_BUILD=TCL_PLUS
  1445.     > CCPLUS=CC
  1446.     191,193c191
  1447.     < MAN_DIR_SEPARATOR=
  1448.     <
  1449.     < LIBOBJS=strftime.o
  1450.     ---
  1451.     > #MAN_DIR_SEPARATOR=.
  1452.  
  1453.    The -D__GNU_LIBRARY solves the srandom problem and I think that the
  1454.    -cckr gets around the prototype error with waitpid (it's crude, but it
  1455.    works). I've forgotten why I needed the strftime.
  1456.  
  1457.    If you want the version of Config.mk that worked for me, send me mail.
  1458.  
  1459. ------------------
  1460.  
  1461. From: Tcl Q&A
  1462. Subject: Q.D13- How do I build expect on Solaris 2.3?
  1463.  
  1464.    From Jeff Abramson (jra@hrcms.jazz.att.com) we are told that,
  1465.  
  1466.      using either SunPro cc 2.0.1 or gcc 2.5.8 with no problems. For
  1467.      SunPro I do:
  1468.  
  1469.     CC=cc ./configure --prefix=directory_of_your_choice
  1470.     make CC=cc
  1471.  
  1472.      For gcc I do:
  1473.  
  1474.     CC="gcc -fwritable-strings" ./configure \
  1475.         --prefix=directory_of_your_choice
  1476.     make CC="gcc -fwritable-strings"
  1477.  
  1478. ------------------
  1479.  
  1480. From: Tcl Q&A
  1481. Subject: Q.D14- How do I port Tcl and Tk to a Sequent?
  1482.  
  1483.    From Andrew Swan (aswan@soda.berkeley.edu) we find:
  1484.  
  1485.      For both Tcl and Tk, I used gcc rather than the Sequent cc which is
  1486.      not ansi.
  1487.  
  1488.      For Tcl, there were a couple of problems with the math library.
  1489.      First, the Sequent math library doesn't include the 'fmod' function.
  1490.      I got the source for fmod from ftp.uu.net, put it in the compat
  1491.      subdirectory, and added it to the Makefile. fmod also wanted
  1492.      functions 'isnan' and 'finite' but I just commented those out since
  1493.      I don't believe tcl supports infinity and nan.
  1494.  
  1495.      The other problem with the math library was that it has two copies
  1496.      of the 'tanh' function in it. This is easy to fix by using "ar" to
  1497.      separate the library in to object files and then reconstruct it,
  1498.      leaving one of the copies of tanh out.
  1499.  
  1500.      With those changes, Tcl compiled cleanly and passed all the tests
  1501.      except the scanning tests. Apparently, the *scanf functions are
  1502.      broken in Dynix. The problem is with recognizing the end of octal
  1503.      numbers, and I just let this problem go. Fixing it would probably
  1504.      involve finding source to the *scanf functions and including it.
  1505.  
  1506.      To compile Tk, I had to make a new version of stddef.h including
  1507.      things like wchar_t. I just copied it in to another include
  1508.      directory and put that directory first and then tweaked the copy. Tk
  1509.      also had the math library problem (tanh). Other than those, however,
  1510.      everything compiled cleanly and passed all the tests.
  1511.  
  1512. ------------------
  1513.  
  1514. From: Tcl Q&A
  1515. Subject: Q.D15- How do I get around the symbol table full msg in AU/X 3.0?
  1516.  
  1517.    After getting things compiled on AU/X, you have to be sure to do the
  1518.    links with the -A {factor} arguments which expand the default table
  1519.    allocations. {factor} is the amount by which the compiler multiplies
  1520.    the default allocation. Try -A 2. Contact Walter B. Kulecz, PhD.
  1521.    (wkulecz@medics.jsc.nasa.gov) for more details of his port. 
  1522.  
  1523. ------------------
  1524.  
  1525. From: Tcl Q&A
  1526. Subject: Q.D16- How do I compile Tcl on MS-DOS, MacOS, or other non-UNIX
  1527.     system?
  1528.  
  1529.    Refer to Larry Virden's FAQ (see tcl-faq/part1) or (see tcl-faq/part4)
  1530.    for details concerning tools, finished ports, or mailing lists
  1531.    relating to this topic. 
  1532.  
  1533. ------------------
  1534.  
  1535. From: Tcl Q&A
  1536. Subject: Q.D17- How do I get Tcl to compile on my QNX system?
  1537.  
  1538.    Steve Furr (furr@qnx.com) indicates:
  1539.  
  1540.    For the record, to get TCL to work under QNX, I had to:
  1541.      * Make the _POSIX_SOURCE change indicated for pathname lengths
  1542.      * Change a definition of VARARGS, so the Watcom ANSI C compiler
  1543.        would accept varargs functions used.
  1544.      * Resolve a conflict with error codes defined by QNX.
  1545.  
  1546.      _________________________________________________________________
  1547.  
  1548. End of FAQ
  1549.  
  1550. ---
  1551. Joe V. Moss         | Hm: joe@italia.rain.com  Wk: joe@morton.rain.com
  1552. Morton & Associates |--------------------------------------------------
  1553. 7478 S.W. Coho Ct.  | label  .l -text "Insert cute quote here"
  1554. Tualatin, OR 97062  | button .b -text "OK" -command exit; pack .l .b
  1555.